home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 September / Macworld (1998-09).dmg / Shareware World / Info / For Developers / MacZoop 1.8.3 / More Classes / File Classes / FileMgrUtils.c next >
Text File  |  1998-07-06  |  4KB  |  167 lines

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            FileMgrUtils.c        -- file utilities
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1998, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21. #include    "FileMgrUtils.h"
  22. #include    "MacZoop.h"
  23.  
  24.  
  25. /*****************************************************************************/
  26. // Static methods obtained from MoreFiles- code provided by Apple DTS.
  27. /*****************************************************************************/
  28.  
  29. #pragma mark ----- File Manager Utilities -----
  30.  
  31. /*****************************************************************************/
  32.  
  33. pascal    OSErr    GetDirectoryID(short vRefNum,
  34.                                long dirID,
  35.                                StringPtr name,
  36.                                long *theDirID,
  37.                                Boolean *isDirectory)
  38. {
  39.     CInfoPBRec pb;
  40.     Str31 tempName;
  41.     OSErr error;
  42.  
  43.     /* Protection against File Sharing problem */
  44.     if ( (name == NULL) || (name[0] == 0) )
  45.     {
  46.         tempName[0] = 0;
  47.         pb.hFileInfo.ioNamePtr = tempName;
  48.         pb.hFileInfo.ioFDirIndex = -1;    /* use ioDirID */
  49.     }
  50.     else
  51.     {
  52.         pb.hFileInfo.ioNamePtr = name;
  53.         pb.hFileInfo.ioFDirIndex = 0;    /* use ioNamePtr and ioDirID */
  54.     }
  55.     pb.hFileInfo.ioVRefNum = vRefNum;
  56.     pb.hFileInfo.ioDirID = dirID;
  57.     error = PBGetCatInfoSync(&pb);
  58.     *isDirectory = (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0;
  59.     *theDirID = (*isDirectory) ? pb.dirInfo.ioDrDirID : pb.hFileInfo.ioFlParID;
  60.     return ( error );
  61. }
  62.  
  63. /*****************************************************************************/
  64.  
  65. pascal    OSErr    FSpGetDirectoryID(const FSSpec *spec,
  66.                                   long *theDirID,
  67.                                   Boolean *isDirectory)
  68. {
  69.     return ( GetDirectoryID(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  70.              theDirID, isDirectory) );
  71. }
  72.  
  73.  
  74. /*****************************************************************************/
  75.  
  76. short    GetSFCurVol()
  77. {
  78.     return -(LMGetSFSaveDisk());
  79. }
  80.  
  81. /*****************************************************************************/
  82.  
  83. long    GetSFCurDir()
  84. {
  85.     return LMGetCurDirStore();
  86. }
  87.  
  88.  
  89. Boolean        GetFullPathname(FSSpec* aSpec, Str255 pathname)
  90. {
  91.     // returns the full pathname for the file spec passed. If the file does not exist, this
  92.     // returns FALSE, if it does, it returns TRUE.
  93.     
  94.     DirInfo        blk;
  95.     Str255        dirName;
  96.     OSErr        theErr;
  97.     Boolean     result = TRUE;
  98.  
  99.     pathname[0] = 0;
  100.     
  101.     blk.ioDrParID = aSpec->parID;
  102.     blk.ioNamePtr = dirName;
  103.     
  104.     do
  105.     {
  106.         blk.ioVRefNum = aSpec->vRefNum;
  107.         blk.ioFDirIndex = -1;
  108.         blk.ioDrDirID = blk.ioDrParID;
  109.         
  110.         theErr = PBGetCatInfoSync((CInfoPBPtr) &blk );
  111.         
  112.         if (theErr)
  113.         {
  114.             result = FALSE;
  115.             break;
  116.         }
  117.         
  118.         ConcatPStrings(dirName,"\p:");
  119.         pStrInsert(pathname,dirName);
  120.     }
  121.     while(blk.ioDrDirID != 2);
  122.     if (result)
  123.         ConcatPStrings(pathname,aSpec->name);
  124.     return result;
  125. }
  126.  
  127. /*****************************************************************************/
  128.  
  129.  
  130. OSErr MakeCanonFSSpec ( FSSpec *spec )
  131. {
  132.     OSErr        err ;
  133.     
  134.     err = FSMakeFSSpec( spec->vRefNum,
  135.                         spec->parID,
  136.                         spec->name,
  137.                         spec ) ;
  138.     return noErr ;
  139. }
  140.  
  141. /*****************************************************************************/
  142.  
  143. Boolean SameFile ( FSSpec *spec1, FSSpec *spec2 )
  144. {
  145.     if (spec1->vRefNum != spec2->vRefNum)
  146.         return false;
  147.     if (spec1->parID != spec2->parID)
  148.         return false;
  149.     if ( !EqualString( spec1->name, spec2->name, false, true ) )
  150.         return false;
  151.     return true;
  152. }
  153.  
  154. /*****************************************************************************/
  155.  
  156. void        pStrInsert(StringPtr dest,StringPtr src)
  157. {
  158.     // inserts <src> at the beginning of <dest>
  159.     
  160.     BlockMoveData(dest + 1,dest + *src + 1,*dest);
  161.     BlockMoveData(src + 1,dest + 1,*src);
  162.     *dest += *src;
  163. }
  164.  
  165. /*****************************************************************************/
  166.  
  167.